/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:54 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class Nguoidung_nhomDAL : SqlProvider<Nguoidung_nhomEntity>
    {
        static Nguoidung_nhomDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Nguoidung_nhomEntity entity = new Nguoidung_nhomEntity();
				entity.FK_iNguoidungID = Int64.Parse("0"+dr["FK_iNguoidungID"].ToString());
				entity.FK_iNhomnguoidungID = Int16.Parse("0"+dr["FK_iNhomnguoidungID"].ToString());
                return entity;
            };
        }
        public static List<Nguoidung_nhomEntity> GetByFK_iNguoidungID(Int64 FK_iNguoidungID)
        {
            string cmdName = "spNguoidung_nhom_GetByFK_iNguoidungID";
            SqlParameter p = new SqlParameter("@FK_iNguoidungID", FK_iNguoidungID);
            List<Nguoidung_nhomEntity> lst = GetList(cmdName, p);
            return lst;
        }
        public static List<Nguoidung_nhomEntity> GetByGetBysKyHieuNhomnguoidung(String sKyhieu)
        {
            string cmdName = "spNguoidung_nhom_GetBysKyHieuNhomnguoidung";
            SqlParameter p = new SqlParameter("@sKyhieu", sKyhieu);
            List<Nguoidung_nhomEntity> lst = GetList(cmdName, p);
            return lst;
        }
        public static List<Nguoidung_nhomEntity> GetByFK_iNhomnguoidungID(Int64 FK_iNhomnguoidungID)
        {
            string cmdName = "spNguoidung_nhom_GetByFK_iNhomnguoidungID";
            SqlParameter p = new SqlParameter("@FK_iNhomnguoidungID", FK_iNhomnguoidungID);
            List<Nguoidung_nhomEntity> lst = GetList(cmdName, p);
            return lst;
        }
        public static Nguoidung_nhomEntity GetByFK_iNguoidungIDAndFK_iNhomnguoidungID(Int64 FK_iNguoidungID, Int64 FK_iNhomnguoidungID)
        {
            string cmdName = "spNguoidung_nhom_GetByFK_iNguoidungIDAndFK_iNhomnguoidungID";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iNguoidungID", FK_iNguoidungID);
            p[1] = new SqlParameter("@FK_iNhomnguoidungID", FK_iNhomnguoidungID);
            Nguoidung_nhomEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Nguoidung_nhomEntity> GetAll()
        {
            string cmdName = "spNguoidung_nhom_Get";
            return GetList(cmdName);
        }
        
        public static int Add(Nguoidung_nhomEntity entity)
        {
            string cmdName = "spNguoidung_nhom_Insert";
            return Run(cmdName,false,initParams(entity));

        }
        public static bool Edit(Nguoidung_nhomEntity entity)
        {
            string cmdName = "spNguoidung_nhom_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 FK_iNguoidungID, Int64 FK_iNhomnguoidungID)
        {
            string cmdName = "spNguoidung_nhom_Delete";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iNguoidungID", FK_iNguoidungID);
            p[1] = new SqlParameter("@FK_iNhomnguoidungID", FK_iNhomnguoidungID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Nguoidung_nhomEntity entity)
        {
            SqlParameter[] p = new SqlParameter[2];
			p[0] = new SqlParameter("@FK_iNguoidungID", entity.FK_iNguoidungID);
			p[1] = new SqlParameter("@FK_iNhomnguoidungID", entity.FK_iNhomnguoidungID);
            return p;
        }
        #endregion
       
    }
}